<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="controller.sesameDataConnector.AbstractDataConnector"%>
<%@page import="org.openrdf.model.impl.URIImpl"%>
<%@page import="model.Vocabulary"%>
<%@page import="org.openrdf.model.URI"%>
<%@page import="org.myontology.controller.SesameSession"%>
<%@page import="java.util.Properties"%>
<%@page import="javax.mail.Session"%>
<%@page import="javax.mail.internet.InternetAddress"%>
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.Transport"%>
<%@page import="org.openrdf.repository.RepositoryResult"%>
<%@page import="org.openrdf.model.Statement"%>

<%@page import="org.myontology.init.Globals"%>
<%@page import="javax.mail.Authenticator"%>
<%@page import="org.myontology.controller.Mailer"%>
<%@page import="org.apache.log4j.Logger"%>
<%@page import="org.myontology.controller.WebAttributeHolder"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Password recovery</title>
</head>
<body>

<%

	RepositoryResult<Statement> statements=null;
	String result = null;
	
	




String userid = request.getParameter("userid");
try {
	URI user = new URIImpl(Vocabulary.USER_NAMESPACE+userid);
	try {
		statements = AbstractDataConnector.getStandardConnection().getStatements(user, Vocabulary.HASEMAIL, null, false);
		if (statements.hasNext()){
			Statement st = statements.next();
			result = st.getObject().stringValue();
		}
	} catch (Exception e) {
		throw e;
	}
	finally {
		if (statements!=null)
			statements.close();
	}
String mail = result;

try {
	statements = AbstractDataConnector.getStandardConnection().getStatements(user, Vocabulary.HASPWD, null, false);
	if (statements.hasNext()){
		Statement st = statements.next();
		result = st.getObject().stringValue();
	}
} catch (Exception e) {
	throw e;
}
finally {
	if (statements!=null)
		statements.close();
}

String pwd = result;

if (mail==null || pwd == null)
	throw new Exception();



// -------------- email to myontology-team: -----------------



String text = "Your password is:\n\n"+pwd;




Mailer mailer = new Mailer();
mailer.setLogger(Logger.getLogger(Mailer.class));
mailer.mail(mail,"myOntology: Password recovery",text,new WebAttributeHolder(request));

out.println("Your password has been sent to: "+mail);

}
catch (Exception e) {
	
	out.println("Sorry, but an error occured!");
}
%>

</body>
</html>